Page({
    data: {
        price: 0,
        show: false,
        radio: '',
        fileList: [],
        allow_upload: false, //允许上传图片,radio===3时允许
        max_count: 2, //付款凭证图片可上传数量
    },
    onClickButton() {
        this.setData({ show: true })
    },
    onClose() {
        this.setData({ show: false })
    },
    onClick(event) {
        const { name } = event.currentTarget.dataset;
        if (parseInt(name) == 3) {
            this.setData({ allow_upload: true })
        } else {
            this.setData({ allow_upload: false, fileList: [] })
        }
        this.setData({
            radio: name,
        });
    },
    clickUpload() {
        if (parseInt(this.data.radio) !== 3) {
            wx.showToast({
                title: '仅线下支付允许上传凭证',
                icon: 'none'
            })
        }
    },
    afterRead(event) {
        const { file } = event.detail;
        let { fileList = [] } = this.data;
        file.forEach(item => {
            fileList.push(item);
        })
        this.setData({ fileList });
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        // wx.uploadFile({
        //     url: 'https://example.weixin.qq.com/upload',
        //     filePath: file.url,
        //     name: 'file',
        //     formData: { user: 'test' },
        //     success(res) {
        //         // 上传完成需要更新 fileList
        //         const { fileList = [] } = this.data;
        //         fileList.push({ ...file, url: res.data });
        //         this.setData({ fileList });
        //     },
        // });
    },
    delete_image(e) {
        let { fileList = [] } = this.data;
        fileList.splice(e.detail.index, 1);
        this.setData({ fileList });
    },
    onLoad: function(options) {

    }
})